﻿using System;
using System.Security.Authentication;
using K9Nano.MultiTenancy;

namespace K9Nano.Runtime
{
    public interface ISessionContext
    {
        /// <summary>
        /// Id of current tenant or null for host
        /// </summary>
        Guid? TenantId { get; }

        /// <summary>
        /// Id of current tenant or throw Exception for host
        /// </summary>
        /// <exception cref="AuthenticationException"></exception>
        Guid RequiredTenantId { get; }

        /// <summary>
        /// Id of current tenant or null for host
        /// </summary>
        Guid? UserId { get; }

        /// <summary>
        /// Id of current tenant or throw Exception for host
        /// </summary>
        /// <exception cref="AuthenticationException"></exception>
        Guid RequiredUserId { get; }

        string UserName { get; }

        string UserFullName { get; }

        /// <summary>
        /// Gets current multi-tenancy side.
        /// </summary>
        EMultiTenancySides MultiTenancySide { get; }
        
        /// <summary>
        /// 角色
        /// </summary>
        string[] Roles { get; }

        /// <summary>
        /// Scope
        /// </summary>
        string[] Scopes { get; }

        /// <summary>
        /// 客户端ID
        /// </summary>
        string ClientId { get; }

        /// <summary>
        /// Used to change <see cref="TenantId"/> and <see cref="UserId"/> for a limited scope.
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        IDisposable Use(Guid? tenantId, Guid? userId);

        string GetClaim(string claimType);
    }
}